// 轮播图功能
const carouselItems = document.querySelectorAll('.carousel-item');
let currentIndex = 0;

function showCarouselItem(index) {
  carouselItems.forEach((item, i) => {
    if (i === index) {
      item.classList.add('active');
    } else {
      item.classList.remove('active');
    }
  });
}

function nextCarouselItem() {
  currentIndex = (currentIndex + 1) % carouselItems.length;
  showCarouselItem(currentIndex);
}

setInterval(nextCarouselItem, 3000);

// 留言评论功能
const commentForm = document.getElementById('comment-form');
const commentsDiv = document.getElementById('comments');

commentForm.addEventListener('submit', function (e) {
  e.preventDefault();
  const username = document.getElementById('username').value;
  const comment = document.getElementById('comment').value;

  const commentElement = document.createElement('div');
  commentElement.classList.add('comment');
  commentElement.innerHTML = `<p><strong>${username}:</strong> ${comment}</p >`;

  commentsDiv.appendChild(commentElement);

  commentForm.reset();
});